<template>
    <div>
        <h1>房型修改</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房型名称</td>
                    <td><input type="text" v-model="info.houseTypeName"></td>
                </tr>
                 <tr>
                    <td>价格</td>
                    <td><input type="text" v-model="info.price"></td>
                </tr>
                
                <tr>
                    <td>状态</td>
                    <td><input type="radio" name="bb" value="1" v-model="info.state">有
                        <input type="radio" name="bb" value="0" v-model="info.state">无
                    </td>
                </tr>
               <tr>
                    <td>建筑面积</td>
                    <td><input type="text" v-model="info.area"></td>
                </tr>
                 <tr>
                    <td>入住人数</td>
                    <td><input type="text" v-model="info.people"></td>
                </tr>
                
                <tr>
                    <td></td>
                    <td><input type="button" value="修改" @click="Update"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue';
import axios from 'axios';
import moment from 'moment';
import { useRoute,useRouter } from 'vue-router';
let router = useRouter();
let route = useRoute();

let info:any= ref({
    id: 0,
  houseTypeName: "",
  "price": '',
  "photo": "",
  "isWin": '',
  "isDel": '',
  "state": '', 
  "area": '',
  "people": '',
  "themeId": ''
});


onMounted(()=>{
    Fan();
})


const Fan=()=>{
    axios({
        url:'https://localhost:7058/api/Hotel/GetHotelDtoFind',
        method:'get',
        params:{
            id:route.query.id,
        }
    })
    .then((res)=>{
        console.log(res.data);
        Object.assign(info.value,res.data)
        // info.value = res.data
    })
    .catch((err)=>{
        console.log(err)
    })
}

const Update=()=>{
  
    axios({
        url:'https://localhost:7058/api/Hotel/Update',
        method:'put',
        data:info.value,
    })
    .then((res)=>{
        console.log(res)
        if(res.data>0)
        {
            alert("用户修改成功啦");
            router.push('/hotelshow');
            return;
        }
        else{
            alert("用户修改失败了")
            return;
        }
    })
    .catch((err)=>{
        console.log(err);
    })
}
</script>

<style scoped>

</style>